home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue61 / Actions / ActionLessAppU.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-05-16  |  1.1 KB  |  50 lines

  1. unit ActionLessAppU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     edtEntry: TEdit;
  12.     Label1: TLabel;
  13.     lstEntries: TListBox;
  14.     btnAddString: TButton;
  15.     procedure btnAddStringClick(Sender: TObject);
  16.     procedure edtEntryChange(Sender: TObject);
  17.   private
  18.     { Private declarations }
  19.   public
  20.     { Public declarations }
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.DFM}
  29.  
  30. procedure TForm1.btnAddStringClick(Sender: TObject);
  31. begin
  32.   lstEntries.Items.Add( Trim( edtEntry.Text ) );
  33.   //Give focus back to edit
  34.   edtEntry.SetFocus;
  35.   //Highlight edit contents so it can be replaced by overtyping
  36.   edtEntry.SelectAll;
  37.   //Trigger edit's OnChange to ensure button
  38.   //is enabled or disabled as appropriate
  39.   edtEntry.OnChange( edtEntry )
  40. end;
  41.  
  42. procedure TForm1.edtEntryChange(Sender: TObject);
  43. begin
  44.   btnAddString.Enabled :=
  45.     ( Length( Trim( edtEntry.Text ) ) > 0 ) and
  46.     ( lstEntries.Items.IndexOf( Trim( edtEntry.Text ) ) = -1 )
  47. end;
  48.  
  49. end.
  50.